﻿#include "EditorAbilityGroupViewModel.h"

#include "Framework/Editor.h"

#include "EditorAbilityGroupModel.h"

#include "Ability/EditorAbilityModel.h"
#include "Ability/EditorAbilityViewModel.h"
#include "Object/NewObject.h"

#include "Asset/EditorDefaultPackage.h"
#include "Widgets/Splitable/EditorSplitableLayoutModel.h"
#include "Widgets/Splitable/EditorSplitableLayoutViewModel.h"

void REditorAbilityGroupViewModel::BindModel(TSharedObjectPtr<REditorAbilityGroupModel> InModel)
{
    Super::BindModel(InModel);
    Model= InModel;

    Layout=NewObject<REditorSplitableLayoutViewModel>(this);
    Layout->OnBindItemViewModel.BindLambda(
        [this](RObjectPtr InAbilityModel)-> RObjectPtr /*Abillity view model*/
        {

            TSharedObjectPtr<REditorAbilityModel> AbilityModel = InAbilityModel;
            TSharedObjectPtr<REditorAbilityViewModel> AbilityViewModel = NewObject<REditorAbilityViewModel>(
                REditor::Get()->GetViewModelClass(AbilityModel->GetClass())
                ,this);
            AbilityViewModel->BindModel(AbilityModel);
            return AbilityViewModel;
        }
    );
    Layout->BindModel(Model->GetLayout());

    ExpandedIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconChevronDown");
    CollapsedIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconChevronRight");
    MoreIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconEllipsis");
}

float REditorAbilityGroupViewModel::GetAbilityTitleHeight()
{
    return Model->GetAbilityTitleHeight();
}

TSharedObjectPtr<RTexture2D> REditorAbilityGroupViewModel::GetExpandIcon(bool bExpanded) const
{
    return bExpanded ?  ExpandedIcon : CollapsedIcon;
}

TSharedObjectPtr<REditorSplitableLayoutViewModel> REditorAbilityGroupViewModel::GetLayout()
{
    return Layout;
}
